<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script>
    function draw() {
      var ctx = document.getElementById('canvas').getContext('2d')
      var img = new Image()
      img.src = 'https://mdn.mozillademos.org/files/222/Canvas_createpattern.png'
      img.onload = function() {
        var ptn = ctx.createPattern(img, 'repeat')
        ctx.fillStyle = ptn
        ctx.fillRect(0, 0, 150, 150)
      }
    }
  </script>
</head>
<body onload="draw()">
  <canvas id="canvas" width="150" height="150"></canvas>
</body>
</html>